<?php /* Template Name: Team */ ?>

<?php get_header(); ?>
    
<?php 

    //VARS
    $members_counter = 0;

    //SETTTINGS
    $result_cmb_kodax_team_member_num = get_post_meta($post->ID, 'cmb_kodax_team_member_num', true);
    $result_cmb_kodax_team_member = get_post_meta($post->ID, 'cmb_kodax_team_member', true);
    $result_cmb_kodax_team_info = get_post_meta($post->ID, 'cmb_kodax_team_info', true);


    //COUNT TEAM MEMBERS TO SHOW
    $members_to_show_num = 0;
    foreach($result_cmb_kodax_team_member as $value) {
        if (isset($value['show'])) $members_to_show_num++;
    }

    //SET CONTAINER CLASS
    $members_container_class = "";
    $members_container_class_last = "";
    switch ($members_to_show_num) {
        case 1:
            $members_container_class = "full";
            break;
        case 2:
            $members_container_class = "half";
            break;
        case 3:
            $members_container_class = "third";
            break;
        default:
            $members_container_class = "fourth";
            break;
    }

    // var_dump($members_container_class);


?>

        <!-- start main-container -->
        <div class="main-container">
            <!-- start main wrapper -->
            <div class="main wrapper clearfix">
                <!-- start main-content -->
                <div class="main-content full">
                    <!-- clearfix -->
                    <div class="clearfix">

        
                        <!-- MAIN LOOP -->
                        <?php while ( have_posts() ) : the_post(); ?>


                        	<h1><?php the_title(); ?></h1>
                        	<?php the_content(); ?> 

							<br/>
                            <?php 
                                for ($i = 0; $i < $result_cmb_kodax_team_member_num; $i++) {

                                    if (isset($result_cmb_kodax_team_member[$i]['show'])) {
                                        $members_container_class_last = "";
                                        $members_counter++;

                                        // var_dump($members_counter%4);

                                        //set last class
                                        if ($members_to_show_num < 5) {
                                            if ($members_counter == $members_to_show_num) $members_container_class_last = " last";
                                        } else {
                                           if ( ($members_counter%4) === 0)  $members_container_class_last = " last";
                                        }

                                        if ( ($members_counter === 1) || (($members_counter-1)%4 === 0) ) { echo '<div class="clearfix">'; }

                                    ?>
                                    

                                        <div class="<?php echo $members_container_class . $members_container_class_last; ?> boxed">
                                            <img src="<?php echo $result_cmb_kodax_team_member[$i]['image']; ?>" alt="Mock" />
                                            <div class="inner-box">
                                                <h4><?php echo $result_cmb_kodax_team_member[$i]['name']; ?></h4>
                                                <h5><?php echo $result_cmb_kodax_team_member[$i]['title']; ?></h5>
                                                <em><?php echo do_shortcode($result_cmb_kodax_team_member[$i]['description']); ?></em>

                                                <?php 

                                                    if (isset($result_cmb_kodax_team_member[$i]['show_social_links'])) {

                                                        echo '<ul class="social-link">';

                                                        for ($n = 0; $n < count($result_cmb_kodax_team_member[$i]['social_links']); $n++) { 
                                                        ?>
                                                            <li><a href="<?php echo $result_cmb_kodax_team_member[$i]['social_links'][$n][1]; ?>" target="_blank"><em class="fa <?php echo $result_cmb_kodax_team_member[$i]['social_links'][$n][0]; ?>"></em></a></li>
                                                        <?php
                                                        }

                                                        echo '</ul>';
                                                            
                                                    }

                                                ?>
                                                
                                            </div>
                                        </div>
                                        
                                    
                                    <?php
                                        if ( ($members_counter%4 === 0) || ($members_counter == $members_to_show_num)) { echo '</div>'; }
                                    }
                                }  
                            ?>


                        	
                        	<?php 

                                if (isset($result_cmb_kodax_team_info['show_more_team_info'])) {
                                ?>
                                    <div class="text-seperator">
                                        <h5><?php echo $result_cmb_kodax_team_info['title']; ?></h5>
                                    </div>
                                    
                                    <div class="clearfix">
                                        <?php echo do_shortcode($result_cmb_kodax_team_info['text']); ?>
                                    </div>                          
                                <?php
                                }

                            ?>
                        	
                        	
        	                	
        				
                        <?php endwhile; ?>
                        <!-- END LOOP -->
                        
    	
                    </div>
                    <!-- end clearfix -->    
                </div>
                <!-- end main-content -->              
            </div>
            <!-- end main wrapper -->
        </div> 
        <!-- end main-container -->
 
    	
    	
<?php get_footer(); ?>
